<style>
  .wait{cursor:wait !important}.wait *{cursor:wait}#win-sign-personal .unit
  .l{width:70px}#win-sign-personal .unit .r{width:390px}#win-sign-personal
  .hint{color:#999;font-size:12px;margin:8px 0}#ipt-sign-personal{width:378px;height:96px}
</style>
<div data-focus="true" class="form">
  <p class="alert">
    请在下方文本框内输入个性签名。
  </p>
  <div class="unit">
    <div class="l">
      <p class="subtitle">
        个性签名
      </p>
    </div>
    <div class="r">
      <textarea id="ipt-sign-personal" data-name="个性签名" data-length="1,127"
      data-placeholder="请输入个性签名" class="cont">
      </textarea>
      <p class="hint">
        请输入个性签名。签名中不得包含令人反感的信息，且长度应在1到127个字符之间。
      </p>
    </div>
    <span class="clearfix">
    </span>
  </div>
  <div class="unit">
    <div class="l">
      <p class="subtitle">
        同步推送
      </p>
    </div>
    <div class="r">
      <div class="switch active">
        <p>
          是
          <b>
          </b>
          否
        </p>
        <div>
        </div>
      </div>
      <p class="hint">
        当开启同步推送时，系统会自动将新签名推送至漂流瓶。
      </p>
    </div>
    <span class="clearfix">
    </span>
  </div>
  <div class="unit-tool">
    <div class="l">
      <button class="btn success do">
        <i class="icon white icon-ok-circle">
        </i>
        提交修改
      </button>
    </div>
    <div class="r">
    </div>
    <span class="clearfix">
    </span>
  </div>
</div>
<script>
  system.tv = function() {
    "use strict";
    var win = $("#win-sign-personal");
    var ipt = $("#ipt-sign-personal");
    var area = $("#block-user-left").find("p.desc").eq(0);
    var form = win.find("div.form").eq(0);
    var swi = form.find("div.switch").eq(0);
    swi.click(function() {
      var elem = $(this);
      if (!elem.hasClass("active")) {
        elem.addClass("active")
      } else {
        elem.removeClass("active")
      }
    });
    form.setup({
      finish: function() {
        ipt.val($.trim(area.text()))
      },
      callback: function() {
        var sign = $.parseSafe(ipt.val());
        var text = "info::数据同步中...";
        $.info(text);
        win.info(text);
        $.post("api/user/signSubmit", {
          sign: sign
        }).done(function(data) {
          if ( !! data.success) {
            $.info("success::个性签名修改成功。");
            if (swi.hasClass("active")) {
              system.port.newMail && system.port.newMail.abort();
              system.port.newMail = $.post("api/mail/newDrift", {
                content: sign + "（来自签名推送）"
              })
            }
            m.refreshPart();
            $("#block-user-left").find("p.desc").text(sign);
            $("#curtain").click()
          } else {
            $.info("error::" + data.result);
            win.info({
              type: "error",
              text: data.result
            })
          }
        }).fail(function() {
          $.info("error::同服务器通信失败。请于稍后重试。");
          win.info({
            type: "error",
            text: "同服务器通信失败。请于稍后重试。"
          })
        })
      }
    })
  } ();
</script>